<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>岗位新增或者修改页面</title>
    <script src="../../../../../res/js/jquery-3.4.1.min.js"></script>
    <script  src="../../../../../res/layui/layui.js" charset="utf-8"></script>
    <script src="../../../../../res/js/Tools.js"></script>
    <link href="../../../../../res/layui/css/layui.css" media="all" rel="stylesheet">
    <link href="../../../../../res/echarts/eleTree.css" rel="stylesheet"/>
    <script src="../../../../../res/echarts/eleTree.js"></script>
    <link rel="shortcut icon" type="image/x-icon" href="../../../../../res/images/favicon.ico">
    <script charset="utf-8" src="../../../../../res/js/login_common.js"></script>
    <style type="text/css">
        body {
            padding: 10px;
        }
    </style>
</head>
<body>
<form action="" class="layui-form layui-form-pane">
    <input type="hidden" id="pkPostId" name="pkPostId">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">岗位名称</label>
            <div class="layui-input-inline">
            <input autocomplete="off" class="layui-input" lay-reqtext="岗位是必填项，岂能为空？" lay-verify="required"
                   name="postName" id="postName" placeholder="请输入(必填)" type="text">
             </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">部门</label>
            <div class="layui-input-inline">
                <select name="departmentId" id="departmentId" lay-verify="required" placeholder="请输入(必填)">
                    <option value=“”></option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">岗位领导</label>
            <div class="layui-input-inline">
                <select  name="personnelId" id="personnelId">
                    <option value=""></option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">关键字</label>
            <div class="layui-input-inline" style="float: left">
                <input autocomplete="off" class="layui-input"  name="keyword" id="keyword"
                       placeholder="请输入" type="text">
            </div>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <textarea class="layui-textarea" name="remark" id="remark" placeholder="请输入备注"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn site-demo-active" id="sub" lay-filter="de1" lay-submit="" type="submit">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary layui-bg-red">重置按钮</button>
        </div>
    </div>
</form>
<script>
    var form=null;
    layui.use(['form', 'layedit', 'laydate', 'layer'], function () {
        form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');
        //自定义验证规则
        form.verify({
            content: function (value) {
                layedit.sync(editIndex);
            }
        });

        //监听提交
        form.on('submit(de1)', function (data) {
            // 单击之后提交按钮不可选,防止重复提交
            var DISABLED = 'layui-btn-disabled';
            // 增加样式
            $('.site-demo-active').addClass(DISABLED);
            // 增加属性
            $('.site-demo-active').attr('disabled', 'disabled');
            var url=getRootPath() + "OaOrganizationAction/addOrUpdateOrganization";
            let res=postAjax(url,data.field);
            if(res.code===1){
                parent.layui.table.reload('test');//刷新父页面
                layer.msg("操作成功", {icon: 1});
                const index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                parent.layer.close(index);
            }else{
                layer.msg("操作失败");
            }
            return false;
        });

        //表单取值
        layui.$('#LAY-component-form-getval').on('click', function () {
            var data = form.val('example');
        });
        //加载部门下拉框
        loadType();
        //加载领导下拉框
        loadPerson();

        //修改操作
        var ide = getQueryString("pkPostId");
        if (ide) {
            findById(ide);//修改页面的赋值
        }
        form.render();
        //重新渲染表单函数
        function renderForm() {
            layui.use('form', function () {
                var form = layui.form(); //高版本建议把括号去掉，有的低版本，需要加()
                form.render();
            });
        }
        form.render();
    });
    /*赋值*/
    function findById(ide) {
        let url = getRootPath() + "OaOrganizationAction/selectById/" + ide;
        let data=getAjaxById(url);
        $("#pkPostId").val(data.data.pkPostId);
        $("#postName").val(data.data.postName);
        $("#departmentId").val(data.data.departmentId);
        $("#organizationCode").val(data.data.organizationCode);
        $("#personnelId").val(data.data.personnelId);
        $("#keyword").val(data.data.keyword);
        $("#postSort").val(data.data.postSort);
        form.render("select");
    }
    //加载部门下拉框
    function loadType(){
        let url=getRootPath()+"OaDepartmentAction/departmentfindByAll";
        let data=getAjax(url,null);
        $("#departmentId").html("<option value=''></option>");
        $.each(data.data,function(index,item){
            $("#departmentId").append("<option value='"+item.pkDepartmentId+"'>"+item.departmentName+"</option>");
        });
    }
    /*所有人的下拉框*/
    function loadPerson(){
        let url=getRootPath()+"OaPersonnelAction/personnelFindByAll";
        let data=getAjax(url,null);
        $("#personnelId").html("<option value=''></option>");
        $.each(data.data,function(index,item){
            $("#personnelId").append("<option value='"+item.pkPersonnelId+"'>"+item.personnelName+"</option>");
        });
    }
</script>
</body>
</html>